package nju.mscs.businesslogic;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;

import nju.mscs.data.Configration;
import nju.mscs.data.DataServerManager;
import nju.mscs.data.NetClientManager;

public class DS implements DataSynchronism{
	//sprivate final int INI =Integer.parseInt(Configration.getIniKey("INI"));
	NetClientManager ncm;
	public DS(){
		ncm=new NetClientManager();
	}
	public boolean downLoad() {
		// TODO Auto-generated method stub
		try {
			LogIn.db=ncm.getDatabase(LogIn.num);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(LogIn.db!=null)
			return true;
		else
			return false;
	}

	public boolean update() {
		// TODO Auto-generated method stub
		boolean bool=true;
		try {
			ncm.upload(LogIn.num, LogIn.db);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			bool=false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			bool=false;
		}
		try {
			new DataServerManager().savaDate(LogIn.dbFile, LogIn.db);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
}
